//公共厕所拆除、关闭许可审批


//给tabPanel添加事件，tab变换的时候，
//触发事件
function addEventListenerToTab(){
	var tabPanel = parent.Ext.getCmp('centerPanel');
	if(tabPanel){
		if(!tabPanel.hasListener('tabchange'))
			tabPanel.addListener('tabchange',changeEvent);
	}
}

//重写setTimeout方法，以使能够传递参数
//IE下不能传递参数
function setTimeoutForIE(pFunction, iTime, params){
     var fuckIE = function(){
             pFunction(params);    
      }
      var pTimeout = setTimeout(fuckIE, iTime);
      return pTimeout;
}

 
//事件的响应
function changeEvent(obj){
	var item = obj.getActiveTab();
	var id = item.id;
	 if (id == 'csdlwj_sjcl'){ //转向收件材料
		var main = parent.document.getElementById('gzscsglwyhlzsqb_formIframe').contentWindow.document;
		var field = main.getElementsByName('id')[0];
		if(main){
			if(field){
				//var QyId = main.getElementsByName('SR_DLWJSQB_QYBH')[0].value; 
				var AjId = main.getElementsByName('id')[0].value; 
				item.setDisabled(false);
				changeUrlAndReload(item,AjId);
			}else{
				parent.Ext.getCmp('centerPanel').setActiveTab(0);
				item.setDisabled(true);
				Ext.Msg.alert('系统提示','请先保存基本信息表单，再进行呈批表的查看！');
			}
		}
	}else if(id == 'SHOW_GIS'){  //转向webgis
		var main = parent.document.getElementById('gzscsglwyhlzsqb_formIframe').contentWindow.document;
		var objectId = main.getElementsByName('id')[0];
		if(main && objectId){
			item.setDisabled(false);
			setTimeout(copy2Gis,1000);
		}else{
			item.setDisabled(true);
		}
	}else if(id == 'gzscsglwyhlzcpb_form'){ //转向呈批表
		var main = parent.document.getElementById('gzscsglwyhlzsqb_formIframe').contentWindow.document;
		var field = main.getElementsByName('id')[0];
		if(main && field && field.value !=''){
			item.setDisabled(false);
			setTimeoutForIE(copyElement2Cpb,1500,item);
		}
		else{
			parent.Ext.getCmp('centerPanel').setActiveTab(0);
			item.setDisabled(true);
			Ext.Msg.alert('系统提示','请先保存基本信息表单，再进行呈批表的查看！');
		}
	}
}

//根据模板编号、案件编号、企业编号
//对收件材料表单重新定向
function changeUrlAndReload(item,AjId,QyId){
	var isupdate="";//环节名称对文书的操作参数
	var taskid=parent.WF_CONFIG.taskInstDbid;
    if(WF_CONFIG.activityName!="jbrcs" && WF_CONFIG.activityName!="cksa" || taskid==""){
    	isupdate="false";
    }
	if(!Ext.isEmpty(AjId)){
		item.setDisabled(false);
		if(item){
			var templateCode = WF_CONFIG.templateCode;
			var src = 'yw-com-sjcllist!ywList.action?tplcode='+templateCode+'&ajid='+AjId+'&isUpdate='+isupdate;
			parent.Ext.getDom("csdlwj_sjclIframe").src = src;
			//parent.Ext.getDom("csdlwj_sjclIframe").contentWindow.location.href = src;
		}
	}else{
		parent.Ext.getCmp('centerPanel').setActiveTab(0);
		item.setDisabled(true);
		Ext.Msg.alert('系统提示','请先保存基本信息表，后再查看收件材料表！');
	}
}

//针对webgis页面
function copy2Gis(){
	var main = parent.document.getElementById('gzscsglwyhlzsqb_formIframe').contentWindow.document;
	var gis = parent.document.getElementById('SHOW_GISIframe').contentWindow.document;
	var acceptNo = main.getElementsByName('SS_CCGBSQB_ACCEPT_NO')[0].value;
	var templateCode = WF_CONFIG.templateCode;
	var id = main.getElementsByName('id')[0].value;
	if(gis){
		//var ano = gis.getElementsByName('acceptNo')[0].value;
		//var ajid = gis.getElementsByName('id')[0].value;
		//var tid = gis.getElementsByName('templateCode')[0].value;
		//if(ano != acceptNo && ajid != id && tid != templateCode){
			//var src = ctx+'/gzcgwsp/csdlwj/flex.jsp?acceptNo='+acceptNo+'&templateCode='+templateCode+'&id='+id ;
			//parent.Ext.getDom("SHOW_GISIframe").contentWindow.location.href = src;
		//}
		var src = ctx+'/gzcgwsp/csdlwj/flex.jsp?acceptNo='+acceptNo+'&templateCode='+templateCode+'&id='+id ;
		parent.Ext.getDom("SHOW_GISIframe").contentWindow.location.href = src;
  	}
}

//验证提交的表单
function checkElementBeforeSubmit(){
	var obj;
	var gcmc = document.getElementsByName('SS_CCGBSQB_GCMC')[0];
	var sqrmc = document.getElementsByName('SS_CCGBSQB_SQDW')[0];
	var sqrsfz = document.getElementsByName('SS_CCGBSQB_JGBMSFZ')[0];
	var sqrtel = document.getElementsByName('SS_CCGBSQB_SQR_TEL')[0];
	if(gcmc.value == ''){
		obj = {
			result:false,
			text:'系统提示：公厕名称不能为空！',
			target:gcmc
		};
		return obj;
	}
	if(sqrmc.value == ''){
		obj = {
			result:false,
			text:'系统提示：申请人名称不能为空！',
			target:sqrmc
		};
		return obj;
	}
	if(sqrtel.value == ''){
		obj = {
			result:false,
			text:'系统提示：电话不能为空！',
			target:sqrtel
		};
	   return obj;
	}
	
	if(sqrsfz.value == ''){
		obj = {
			result:false,
			text:'系统提示：组织机构代码或自然人身份证号码不能为空！',
			target:sqrsfz
		};
	   return obj;
	}
	
	obj = {
		result:true,
		text:'验证通过',
		target:null
	};
	return obj;
}

//验证收件材料
function myValidate(id){
	var sjcl = parent.document.getElementById(id).contentWindow;
	var _sjclList = sjcl.document.getElementById('sjcl_list');
	var obj = null;
	if(_sjclList != null)
	{
		for(var i=1;i<_sjclList.rows.length;i++)
		{
			var _childNodes=_sjclList.rows[i].cells;
			if(_sjclList.rows[i].hasExists == 'false')
			{
			    var alertText =  '*'+_childNodes[1].innerHTML+'\u6CA1\u6709\u4E0A\u4F20,\u8BF7\u5148\u4E0A\u4F20\u8BE5\u9644\u4EF6!';
				obj = {text:alertText,result:false};
				return obj;
			}
		}
		obj = {text:null,result:true};
	}
    return obj;
}

//从呈批表中复制相关的信息到基本表单中
function copyElementFromCpb2Sqb(){
	var sqb = parent.document.getElementById('gzscsglwyhlzsqb_formIframe').contentWindow.document;
	var cpbIframe = parent.document.getElementById('gzscsglwyhlzcpb_formIframe');//.contentWindow.document;
	if(cpbIframe != null && cpbIframe != ''){
		var cpb = parent.document.getElementById('gzscsglwyhlzcpb_formIframe').contentWindow.document;
		var id = sqb.getElementsByName('id')[0].value;
		if(id != null && id != ''){
			if(sqb && cpb){
				//呈批时间
				sqb.getElementsByName('SS_CCGBSQB_CPSJ')[0].value = cpb.getElementsByName('SS_CCGBCPB_cpsj')[0].value;
				//答复时间
				sqb.getElementsByName('SS_CCGBSQB_DFSJ')[0].value = cpb.getElementsByName('SS_CCGBCPB_dfsj')[0].value;
			}
		}
	}	
}


//从基本表单中复制相关的信息到呈批表中
function copyElement2Cpb(item){
	var sqb = parent.document.getElementById('gzscsglwyhlzsqb_formIframe').contentWindow.document;
	var cpb = parent.document.getElementById('gzscsglwyhlzcpb_formIframe').contentWindow.document;
	var id = sqb.getElementsByName('id')[0].value;
	if(id != null && id != ''){
		item.setDisabled(false);
		if(sqb && cpb){
			
			//受理号
			if(sqb.getElementsByName('SS_CCGBSQB_ACCEPT_NO')[0] && cpb.getElementsByName('SS_CCGBCPB_SLH')[0]){
				cpb.getElementsByName('SS_CCGBCPB_SLH')[0].value = sqb.getElementsByName('SS_CCGBSQB_ACCEPT_NO')[0].value;
			}
			//收件人
			if(cpb.getElementsByName('SS_CCGBCPB_SJR')[0] && sqb.getElementsByName('SS_CCGBSQB_SJR')[0]){
				cpb.getElementsByName('SS_CCGBCPB_SJR')[0].value = sqb.getElementsByName('SS_CCGBSQB_SJR')[0].value;
			}
			//收件时间
			if(cpb.getElementsByName('SS_CCGBCPB_SJSJ')[0] && sqb.getElementsByName('SS_CCGBSQB_SQRQ')[0]){
				cpb.getElementsByName('SS_CCGBCPB_SJSJ')[0].value = sqb.getElementsByName('SS_CCGBSQB_SQRQ')[0].value;
			}
			//公厕名称
			if(cpb.getElementsByName('SS_CCGBCPB_GCMC')[0] && sqb.getElementsByName('SS_CCGBSQB_GCMC')[0]){
				cpb.getElementsByName('SS_CCGBCPB_GCMC')[0].value = sqb.getElementsByName('SS_CCGBSQB_GCMC')[0].value;
			}
			//申请业务
			if(cpb.getElementsByName('SS_CCGBCPB_SQYW')[0] && sqb.getElementsByName('SS_CCGBSQB_CBYW')[0]){
				cpb.getElementsByName('SS_CCGBCPB_SQYW')[0].value = sqb.getElementsByName('SS_CCGBSQB_CBYW')[0].value;
			}
			//联系人
			if(cpb.getElementsByName('SS_CCGBCPB_LXR')[0] && sqb.getElementsByName('SS_CCGBSQB_SQDW')[0]){
				cpb.getElementsByName('SS_CCGBCPB_LXR')[0].value = sqb.getElementsByName('SS_CCGBSQB_SQDW')[0].value;
			}
			//联系电话
			if(cpb.getElementsByName('SS_CCGBCPB_LXDH')[0] && sqb.getElementsByName('SS_CCGBSQB_BG_TEL')[0]){
				cpb.getElementsByName('SS_CCGBCPB_LXDH')[0].value = sqb.getElementsByName('SS_CCGBSQB_BG_TEL')[0].value;
			}
			//承办部门
			if(cpb.getElementsByName('SS_CCGBCPB_CBBM')[0] && sqb.getElementsByName('SS_CCGBSQB_CBBM')[0]){
				cpb.getElementsByName('SS_CCGBCPB_CBBM')[0].value = sqb.getElementsByName('SS_CCGBSQB_CBBM')[0].value;
			}
			//呈批时间
			if(cpb.getElementsByName('SS_CCGBCPB_CPSJ')[0] && sqb.getElementsByName('SS_CCGBSQB_CPSJ')[0]){
				cpb.getElementsByName('SS_CCGBCPB_CPSJ')[0].value = sqb.getElementsByName('SS_CCGBSQB_CPSJ')[0].value;
			}
			//公示时间
			if(cpb.getElementsByName('SS_CCGBCPB_GSSJ')[0] && sqb.getElementsByName('SS_CCGBSQB_GSSJ')[0]){
				cpb.getElementsByName('SS_CCGBCPB_GSSJ')[0].value = sqb.getElementsByName('SS_CCGBSQB_GSSJ')[0].value;
			}
			//答复时间
			if(cpb.getElementsByName('SS_CCGBCPB_DFSJ')[0] && sqb.getElementsByName('SS_CCGBSQB_DFSJ')[0]){
				cpb.getElementsByName('SS_CCGBCPB_DFSJ')[0].value = sqb.getElementsByName('SS_CCGBSQB_DFSJ')[0].value;
			}
		}
	}else{
		parent.Ext.getCmp('centerPanel').setActiveTab(0);
		item.setDisabled(true);
		Ext.Msg.alert('系统提示','请先保存基本信息表，后再查看呈批表！');
	}
}
